package com.productivity.model;

import java.awt.geom.Rectangle2D;
import java.nio.FloatBuffer;

import com.productivity.model.common.DrawType;
import com.productivity.model.common.Size3D;
import com.productivity.model.common.Vertex3D;

public abstract class GameObject {
	protected Vertex3D location;
	protected Vertex3D drawOffset;
	protected Size3D size;
	protected Vertex3D[] vertices;
	protected Vertex3D[] normals;
	
	public abstract void update(Map map);
	public abstract DrawType getDrawType();
	public abstract Size3D getModelSize();
	
	public GameObject() {
		location = new Vertex3D();
		drawOffset = new Vertex3D();
		size = new Size3D();
		vertices = null;
	}
	public Vertex3D getDrawOffset() {
		return drawOffset;
	}
	public void setDrawOffset(Vertex3D drawOffset) {
		this.drawOffset = drawOffset;
	}
	public Size3D getSize() {
		return size;
	}
	public void setSize(Size3D size) {
		this.size = size;
	}
	public Vertex3D getLocation() {
		return location;
	}
	public void setLocation(Vertex3D location) {
		this.location = location;
	}
	public Rectangle2D getBounds() {
		return new Rectangle2D.Float(location.getX()-size.getX()/2,location.getY()-size.getY()/2,size.getX(),size.getY());
	}
	public FloatBuffer getVertexBuffer() {	
		if(vertices==null) return null;
		FloatBuffer buff = FloatBuffer.allocate(vertices.length*3);
		for(int i = 0; i < vertices.length;i++) {
			buff.put(vertices[i].getArray());
		}
		buff.rewind();
		return buff;
	}
	public FloatBuffer getNormalBuffer() {	
		if(normals==null) return null;
		FloatBuffer buff = FloatBuffer.allocate(normals.length*3);
		for(int i = 0; i < normals.length;i++) {
			buff.put(normals[i].getArray());
		}
		buff.rewind();
		return buff;
	}
}
